#include <bits/stdc++.h>
// 2025/02/03
// tag: 
// Author: Zhang Muen
using namespace std;

int r, c, snow[102][102];
int length[102][102], dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

int dfs(int x, int y){
    if (length[x][y] != -1)
        return length[x][y];
    length[x][y] = 1;
    for (int i = 0; i < 4; i++){
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 1 && ny >= 1 && nx <= r && ny <= c && snow[x][y] > snow[nx][ny])
            length[x][y] = max(length[x][y], dfs(nx, ny) + 1);
    }
    return length[x][y];
}

signed main()
{
    cin >> r >> c;
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++)
            cin >> snow[i][j];
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++)
            length[i][j] = -1;
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++)
            dfs(i, j);
    int ans = 0;
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++)
            ans = max(ans, length[i][j]);
    cout << ans;
    return 0;
}